//
//  ViewController.m
//  06-UINavgationController
//
//  Created by dllo on 16/7/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "PushViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
  //设置navgationBar的属性
   //1. 标题， 告诉用户， 我这个视图控制器时干什么用的
    self.title = @"我是标题";
    self.navigationItem.title = @"xxxx, hehehhe";
    //2.titleView 标题视图
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"韩旭", @"王煌"]];
    // 标题视图， 修改x， y 对视图本身位置没有影响
    segment.frame = CGRectMake(0, 0, 150, 44);
   self.navigationItem.titleView = segment;
  //3.leftBarButtonItem
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
  //4. rightBarButtonItem
//    self.navigationController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
   //5.
    UIBarButtonItem *barButtonItemTitle = [[UIBarButtonItem alloc] initWithTitle:@"xxxx" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    
    UIBarButtonItem *barButtonItemSystemItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(add:)];
    self.navigationItem.leftBarButtonItems = @[barButtonItemTitle, barButtonItemSystemItem];
    
  // 6. leftBarButtonItems 数组
  // BarButtonItems 数组中放1-2个Item为最优
    
   //7. 隐藏navigationBar YES 隐藏 NO 不隐藏 默认为 NO
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.hidden = NO;
   //8. navigationBar 背景样式 默认为 default
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
   //9.navigationBar 的背景颜色
   self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
   //10.barTintColor Bar的颜色
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
  // 11.tintColor Bar上元素的颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
   //12.translucent 管理半透明效果， YES为开启 NO为关闭
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 0, 200, 200);
    button.backgroundColor = [UIColor blueColor];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    // ios7 以后 默认 为YES iOS6 以前都是 NO
   //设置为YES时， self.view坐标系从原点开始
   //设置为NO时， self.view坐标系从navigationBar开始
//    self.navigationController.navigationBar.translucent = YES;
   //13.改变坐标效果， 与translucent效果一样
    self.edgesForExtendedLayout = UIRectEdgeNone;
   //页面跳转相关
   //1 push pushViewController
   //2 pop popToRootViewControllerAnimated
   //3 viewControllers 存放navigationController里所有的控制器

//    self.navigationController.viewControllers
  // 4. topViewController 栈顶视图控制器 （最后入栈）
  // 5. visibViewController 可见视图控制器  （）
}
- (void)buttonClicked:(UIButton *)button {
  // 视图控制器入栈
    [self.navigationController pushViewController:[[PushViewController alloc] init] animated:YES];
}

- (void)comeBack:(UIBarButtonItem *)barButtonItem {
    NSLog(@"返回");
}
- (void)add:(UIBarButtonItem *)barButtonItem {
    NSLog(@"添加");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
